package com.xiaogao.sys.controller;

import com.xiaogao.common.entity.Result;
import com.xiaogao.security.annotation.HasPerm;
import com.xiaogao.sys.request.dict.data.AddParam;
import com.xiaogao.sys.request.dict.data.UpdateParam;
import com.xiaogao.sys.response.SysDictDataResponse;
import com.xiaogao.sys.service.SysDictDataService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/dict/data")
public class SysDictDataController {
    private final SysDictDataService sysDictDataService;

    @GetMapping("/list/{type}")
    public Result<List<SysDictDataResponse>> querySelective(@PathVariable String type){
        List<SysDictDataResponse> list = sysDictDataService.querySelective(type);
        return Result.success(list);
    }

    @HasPerm("sys:dict:data:add")
    @PostMapping("/add")
    public Result<Object> add(@RequestBody @Validated AddParam addParam) {
        sysDictDataService.add(addParam);
        return Result.success();
    }

    @HasPerm("sys:dict:data:update")
    @PutMapping("/update")
    public Result<Object> update(@RequestBody @Validated UpdateParam updateParam) {
        sysDictDataService.update(updateParam);
        return Result.success();
    }

    @HasPerm("sys:dict:data:delete")
    @PostMapping("/delete")
    public Result<Object> delete(@RequestBody List<String> ids) {
        sysDictDataService.delete(ids);
        return Result.success();
    }
}
